package myself.a002StackAndQueue;

import myself.a000util.Logarithm;

import java.util.Objects;

import static myself.a000util.NodeCollection.SingleNode;


/**
 * @author 叶之越
 * Description
 * Date 2021/1/21
 * Time 20:56
 * Mail 739153436@qq.com
 */
public class DeleteGivenValue {
    public static void main(String[] args) {
        Logarithm.NodeList.checkSingleRemove(DeleteGivenValue.class, "removeValue");
    }

    public SingleNode removeValue(SingleNode head, int value) {
        if (head == null) {
            return null;
        }
        // 如果头结点和目标值相同
        while (Objects.equals(head.t, value)) {
            head = head.next;
        }
        SingleNode cur = head;
        // 中间节点和目标值相同
        while (cur.next != null) {
            while (cur.next != null && Objects.equals(cur.next.t, value)) {
                cur.next = cur.next.next;
            }
            if (cur != null) {
                cur = cur.next;
            }
        }
        return head;
    }
}
